package com.xiaoyin.community.Utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by yinjianping@baidu.com on 2018/7/12.
 *
 * @Description:
 * @Modified By:
 */
public class HttpUtils {
    public static String getParam(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String params = null;
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream(),"utf-8"));
            StringBuilder stirngStringBuilder = new StringBuilder();
            String inputString;
            while((inputString=bufferedReader.readLine()) != null){
                stirngStringBuilder.append(inputString);
            }
            JSONObject jsonObject = JSONObject.parseObject(stirngStringBuilder.toString());
            params=jsonObject.toJSONString();
            System.out.println(params);

        }catch(IOException e){
            e.printStackTrace();
        }
        return params;
    }
}
